package com.t9101DR.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.t9101DR.bean.DrUser;
import com.t9101DR.bean.RoomAddress;
import com.t9101DR.dao.BaseDao;
import com.t9101DR.dao.DrUserDao;

public class DrUserDaoImpl extends BaseDao implements DrUserDao {

	@Override
	public List<DrUser> list(DrUser du) {
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		List<DrUser> list=new ArrayList<DrUser>();
		try {
			conn=getConnection();
			String sql="SELECT\r\n" + 
					"	DrUserId,\r\n" + 
					"	userid,\r\n" + 
					"	DrName,\r\n" + 
					"	userName,\r\n" + 
					"	telephone,\r\n" + 
					"	sex,\r\n" + 
					"	loving,\r\n" + 
					"	loveText,\r\n" + 
					"	birthday,\r\n" + 
					"	constellation,\r\n" + 
					"	blood,\r\n" + 
					"	profession,\r\n" + 
					"	address,\r\n" + 
					"	hobby,\r\n" + 
					"	`password`,\r\n" + 
					"	IDcard \r\n" + 
					"FROM\r\n" + 
					"	druser\r\n" + 
					"WHERE\r\n" + 
					"	1=1   ";
			if(du!=null&&du.getUserid()!="") {
				sql=sql+" and userid= "+du.getUserid()+" ";
			}
			pstmt=conn.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()) {
				DrUser bren=new DrUser();
				bren.setDrUserId(rs.getInt(1));
				bren.setUserid(rs.getString(2));
				bren.setDrName(rs.getString(3));
				bren.setUserName(rs.getString(4));
				bren.setTelephone(rs.getString(5));
				bren.setSex(rs.getInt(6));
				bren.setLoving(rs.getInt(7));
				bren.setLoveText(rs.getString(8));
				bren.setBirthday(rs.getString(9));
				bren.setConstellation(rs.getString(10));
				bren.setBlood(rs.getString(11));
				bren.setProfession(rs.getString(12));
				bren.setAddress(rs.getString(13));
				bren.setHobby(rs.getString(14));
				bren.setPassword(rs.getString(15));
				bren.setIdCard(rs.getString(16));		
				list.add(bren);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			closeAll(conn, pstmt, rs);
		}
		return list;
	}
	

	@Override
	public int add(DrUser du) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int update(DrUser du) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteById(int id) {
		// TODO Auto-generated method stub
		return 0;
	}

}
